#!/bin/sh

if [ $# -ne 2 ]; then
	echo "[usage]\nimport.sh [in_file] [out_file]"
	exit;
fi

FILE_IN=$1
TOEFL_XML_FILE=$2

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<tword>" > $TOEFL_XML_FILE

add()
{
	echo "<word name=\"$WNAME\" lang=\"en\">" >> $TOEFL_XML_FILE
	echo "  <slot type=\"$WTYPE\" lang=\"cn\" mean=\"\">" >> $TOEFL_XML_FILE
	echo "    <example>$EG</example>" >> $TOEFL_XML_FILE
	echo "  </slot>" >> $TOEFL_XML_FILE
	echo "</word>" >> $TOEFL_XML_FILE
}

cat $FILE_IN | while read WNAME WTYPE EG; do
	if [ -n $WNAME ]; then
		add
	fi
done

echo "</tword>\n" >> $TOEFL_XML_FILE

